﻿package com.swss.util;

import java.util.Collections;
import java.util.List;

@SuppressWarnings("unchecked")
public class Pagination<T> implements java.io.Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -2750060187477990827L;

	private int pageno = 1; // 当前页码

	private int pagesize = 15; // 每页行数

	private int rowcount; // 总行数

	private int pagecount; // 总页数

	private boolean useprevious;// 前一页是否能用

	private boolean usebehind;// 后一页是否能用

	private boolean usepage = true;// 是否分页

	private int rangeCount = 5;// 数字部分个数

	private int range[] = null;//当前数字范围

	private String orderBy = "id";

	private String orderType = "desc";
	
	private String url="";//目标地址
	
	private Long astCount;   //资产数量
	
	private Double astAmount; //资产金额

	// the search result
	protected List<T> result = Collections.EMPTY_LIST;

	public int getPageno() {
		return pageno;
	}

	public void setPageno(int pageno) {
		this.pageno = pageno;
	}

	public int getPagesize() {
		return pagesize;
	}

	public void setPagesize(int pagesize) {
		if (pagesize == 0) {// 0-->不分页
			usepage = false;
			pagecount = 1;
			pageno = 1;
			useprevious = false;
			usebehind = false;
		}
		this.pagesize = pagesize;
	}

	public int getRowcount() {
		return rowcount;
	}

	public void setRowcount(int rowcount) {
		this.rowcount = rowcount;
		if (usepage) { // 如果分页
			pagecount = (rowcount % pagesize == 0) ? (rowcount / pagesize)
					: (rowcount / pagesize + 1);
			useprevious = pageno == 1 ? false : true;
			usebehind = pageno == pagecount ? false : true;
		}
	}

	public int getPagecount() {
		return pagecount;
	}

	public void setPagecount(int pagecount) {
		this.pagecount = pagecount;
	}

	public boolean isUseprevious() {
		return useprevious;
	}

	public void setUseprevious(boolean useprevious) {
		this.useprevious = useprevious;
	}

	public boolean isUsebehind() {
		return usebehind;
	}

	public void setUsebehind(boolean usebehind) {
		this.usebehind = usebehind;
	}

	public boolean isUsepage() {
		return usepage;
	}

	public void setUsepage(boolean usepage) {
		this.usepage = usepage;
	}

	public int getRangeCount() {
		return rangeCount;
	}

	public void setRangeCount(int rangeCount) {
		this.rangeCount = rangeCount;
	}

	public int[] getRange() {
		
		if (pagecount > 6) {
			range = new int[5];
			if (pageno <= 4) {
				for (int i = 0; i < 5; i++) {
					range[i] = i + 2;
				}
			} else if (pageno > 4 && pageno < pagecount - 3) {
				range[0] = pageno - 2;
				range[1] = pageno - 1;
				range[2] = pageno;
				range[3] = pageno + 1;
				range[4] = pageno + 2;
			} else {
				for (int i = 0; i < 5; i++) {
					range[i] = pagecount - 5 + i;
				}
			}
		} else {
			range = new int[pagecount];
			for (int i = 0; i < pagecount; i++) {
				range[i] = i + 1;
			}
		}

		return range;
	}

	public void setRange(int[] range) {
		this.range = range;
	}

	public List<T> getResult() {
		return result;
	}

	public void setResult(List<T> result) {
		this.result = result;
	}

	public String getOrderBy() {
		return orderBy;
	}

	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}

	public String getOrderType() {
		return orderType;
	}

	public void setOrderType(String orderType) {
		this.orderType = orderType;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public Long getAstCount() {
		return astCount;
	}

	public void setAstCount(Long astCount) {
		this.astCount = astCount;
	}

	public Double getAstAmount() {
		return astAmount;
	}

	public void setAstAmount(Double astAmount) {
		this.astAmount = astAmount;
	}
    
}